package com.weetop.akly.presenter;

import android.app.Activity;

import com.blankj.utilcode.util.LogUtils;
import com.weetop.akly.base.mvp.BaseModel;
import com.weetop.akly.base.mvp.BaseObserver;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.bean.ApproveItem;
import com.weetop.akly.bean.BaseCountBean;
import com.weetop.akly.bean.DaySignBean;
import com.weetop.akly.bean.SignResultBean;
import com.weetop.akly.bean.WorkGroupBean;
import com.weetop.akly.bean.WorkLogResultBean;
import com.weetop.akly.view.SignView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SignPresent extends BasePresenter<SignView> {
    public SignPresent(SignView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * 获取考勤组列表
     */
    public void getWorkGroupList(){
        addDisposable(apiServer.getWrokGroupList(), new BaseObserver<BaseModel<ArrayList<WorkGroupBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ArrayList<WorkGroupBean>> o) {
                baseView.getWorkGroupListSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * 获取加班申请单列表
     */
    public void overTimeList(HashMap<String, String> map){
        addDisposable(apiServer.overTimeList(map), new BaseObserver<BaseModel<BaseCountBean<ApproveItem>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<BaseCountBean<ApproveItem>> o) {
                baseView.overTimeListSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    /**
     * 日打卡情况
     *
     * @param day 格式：yyyy-MM-dd
     */
    public void getDayCheckinWatch(String day) {
        addDisposable(apiServer.getDateCheckinWatch(day), new BaseObserver<BaseModel<ArrayList<DaySignBean>>>(baseView) {
            @Override
            public void onSuccess(BaseModel<ArrayList<DaySignBean>> o) {
                baseView.getDayCheckinWatchSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
    /**
     * 获取班次列表
     */
    public void getWorkLogList(String groupId){
        addDisposable(apiServer.getWorkLogList(groupId), new BaseObserver<BaseModel<WorkLogResultBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<WorkLogResultBean> o) {
                baseView.getWorkLogListSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }


    /**
     * 签到打卡接口
     */
    public void toSign(Map<String, String> data){
        addDisposable(apiServer.toWorkSign(data), new BaseObserver<BaseModel<String>>(baseView) {
            @Override
            public void onSuccess(BaseModel<String> o) {
                baseView.workSignSuccess();
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
}
